package com.example.understand_compose1.testcase_compose.page

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.understand_compose1.R

// Page2提供列布局和行布局的应用


//data class Message(
//    val author: String,
//    val body: String
//)

@Composable
fun MessageCardByLayout(msg: Message) {
//    没有使用布局时，默认重叠
//    Text(text = msg.author)
//    Text(text = msg.body)

//    Column {
//        Row {
//            Text(text = msg.author)
//            Text(text = msg.body)
//        }
//        Row {
//            Text(text = msg.author)
//            Text(text = msg.body)
//        }
//    }

//    Row {
//        Image(
//            painter = painterResource(R.drawable.ic_launcher_background),
//            contentDescription = "Content Profile Picture"
//        )
//
//        Column {
//            Text(
//                text = msg.author
//            )
//            Text(
//                text = msg.body
//            )
//        }
//    }

    Row(modifier = Modifier.padding(all=8.dp)) {
        Image(
            painter = painterResource(R.drawable.ic_launcher_background),
            contentDescription = "Contact Profile Picture",
            modifier = Modifier
                .size(40.dp)
                .clip(CircleShape)
        )

        Spacer(modifier = Modifier.width(8.dp))

        Column {
            Text(text = msg.author)
            Spacer(modifier = Modifier.height(4.dp))
            Text(text = msg.body)
        }
    }
}

@Preview
@Composable
fun PreviewMessageCardByLayout() {
    MessageCardByLayout(
        msg = Message("Laxi", "core")
    )
}